package com.extension.company.common.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/8/7 16:47
 * 功能：重写的netScrollView ,由于其父布局的和其有滑动冲突。
 */
public class MyNetScrollView extends NestedScrollView {
	public float oldY;
	private int t;
	private float oldX;

	public MyNetScrollView(@NonNull Context context) {
		super(context);
	}

	public MyNetScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
		super(context, attrs);
	}

	public MyNetScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		return super.onInterceptTouchEvent(ev);
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) { //
		int x = (int) ev.getX();
		int y = (int) ev.getY();
		int mLastX = x;
		int mLastY = y;
		switch (ev.getAction()) {
			case MotionEvent.ACTION_DOWN: // 点下的时候，请求nestateScrollview外的父布局不拦截
				getParent().requestDisallowInterceptTouchEvent(true);
				break;
			case MotionEvent.ACTION_MOVE:
				int deltax = x - mLastX;
				int deltay = y - mLastY;
				if (getScrollY() == 0) { //当neStateScrollView滑动到顶端的时候，请求父布局拦截滑动。
					getParent().requestDisallowInterceptTouchEvent(false);
				}
				break;
			case MotionEvent.ACTION_UP:
				break;
			default:
				break;
		}
		return super.dispatchTouchEvent(ev);
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		return super.onTouchEvent(ev);
	}
}
